﻿using Blog.Application.DTO;
using Blog.Application.Service;
using Core.Common;
using Core.Common.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BlogWebApi.Controllers
{

    [Route("api/admin")]
    [ApiController]
    public class AdminController: ControllerBase
    {
        private IUserService _userService;
        public AdminController(IUserService userService)
        {
            _userService = userService;
        }
        [Route("login")]
        [HttpPost]
        public ApiResult Login()
        {
            string account = Request.Form["account"];
            string password = Request.Form["password"];
            try
            {
                UserDTO user = _userService.Login(account, password);
                return ApiResult.Success(user);
            }
            catch (AuthException ex)
            {
                return ApiResult.Error("403", ex.Message);
            }
        }
    }
}
